package org.webequa.core.maple.operator.algebra;

import org.apache.log4j.Logger;
import org.webequa.core.common.operator.algebra.Abs;
import org.webequa.core.maple.operator.MapleUnaryOperator;
import org.webequa.core.maple.quantity.MapleQuantityObject;
import org.webequa.core.maple.quantity.MapleQuantityObjectFactory;

import com.maplesoft.externalcall.MapleException;

public class MapleAbs extends MapleUnaryOperator implements Abs
{
	public MapleAbs()
	{
		super();
	}
	
	@Override
	public void calculate()
	{
		res = null;
		if (getResultSignature()!=null)
		{
			try
			{
				MapleQuantityObject tOp = MapleQuantityObjectFactory.getMapleQuantityObject(operand);
				String mapleJob = "abs("+tOp.getVarName()+"):";							
				res = MapleQuantityObjectFactory.getMapleQuantityObject(getResultSignature(),mapleEngine.evaluate(mapleJob));
				log.info(mapleJob);				
			} catch (MapleException e)
			{
				log.error(e);
				res = null;
			}					
		}
	}
	private static final Logger log = Logger.getLogger(MapleAbs.class);	
}
